import java.util.Arrays;

public class Main {

    //进制转换
    //九进制转换为十进制
    public static void main1(String[] args) {
        int[] num = {2,2,0,2};
        change(num,9,4);//将一个4位数的九进制数字转化为十进制
    }

    private static void change1(int[] num,int n,int len) {
        int ret = 0;
        int w = 1;//权重
        for (int i = 0; i < len; i++) {
            ret += num[i] * w;
            w *= n;
        }
        System.out.println(ret);
    }

    //十进制转换为n进制
    public static void main(String[] args) {
        int[] num = new int[4];
        change(num,9,1478);
    }

    //x为十进制整数
    //num为转化后的储存空间，逆序储存
    //返回一个len代表转化后的长度
    private static void change(int[] num, int n, int x) {
        int len = 0;
        while(x > 0){
            num[len++] = x % n;
            x /= n;
        }
        System.out.println(Arrays.toString(num));
    }

}
